package hc.j2me.ui;


public class SpritesLoc {
	//本数组成员可以为null、一个Sprite实例、或一个Sprite[]
	Object[] sprites;
	
	Object lockObj;
	int moveX, moveY;
	public boolean isMoveIn;
	HCCtrlGameCanvas hccanvas;
	
	public SpritesLoc(Object[] sps, Object lock, HCCtrlGameCanvas hccanvas){
		sprites = sps;
		lockObj = lock;
		this.hccanvas = hccanvas;
	}
	
	public void addSprite(Object sprite){
		if(sprite == null){
			return;
		}
		synchronized (lockObj) {
			for (int i = 0; i < sprites.length; i++) {
				if(sprites[i] == null){
					sprites[i] = sprite;
					return;
				}
			}
			Object[] ns = new Object[sprites.length + 1];
			for (int i = 0; i < sprites.length; i++) {
				ns[i] = sprites[i];
			}
			ns[sprites.length] = sprite;
			sprites = ns;
		}		
	}
	
	public void removeSprite(Object sprite){
		if(sprite == null){
			return;
		}
		synchronized (lockObj) {
			for (int i = 0; i < sprites.length; i++) {
				if(sprites[i] == sprite){
					sprites[i] = null;
					return;
				}
			}
		}
	}
}
